package com.hzcx.app.simplechat.ui.friend.presenter;

import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.model.FriendModel;
import com.hzcx.app.simplechat.ui.friend.bean.FriendBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.ui.friend.contract.FriendContract;
import com.hzcx.app.simplechat.ui.friend.contract.FriendSortContract;
import com.hzcx.app.simplechat.ui.main.bean.FriendRequestCountBean;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class FriendSortPresenter extends BasePresenter<FriendSortContract.View> implements FriendSortContract.Presenter {


    /**
     * 获取好友列表
     *
     * @param context
     * @param type
     */
    @Override
    public void getFriendList(Context context, int type) {
        FriendModel.getFriendBySort(context, null, type + "", new BaseDialogObserver<List<FriendCityBean>>(context) {
            @Override
            protected void onSuccess(List<FriendCityBean> data) {
                mView.friendListResult(data, type);
            }
        });
    }

    /**
     * 对好友列表排序
     */
    private List<FriendCityBean> collectionList(List<FriendCityBean> data, int type) {
        Collections.sort(data, (friendSortBean, t1) -> {
            if (type == 1) {
                return Long.valueOf(friendSortBean.getLogintime()).compareTo(Long.valueOf(t1.getLogintime()));
            } else {
                return Long.valueOf(friendSortBean.getCreatetime()).compareTo(Long.valueOf(t1.getCreatetime()));
            }
        });
        return data;
    }
}
